package com.sinosoft.brokerchannel.server;

import com.sinosoft.brokerchannel.base.common.SystemParamFinal;
import com.sinosoft.brokerchannel.base.server.LogService;
import com.sinosoft.brokerchannel.base.utile.BusinessException;
import com.sinosoft.brokerchannel.entity.vo.*;
import com.sinosoft.brokerchannel.server.impl.IusServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * @需求名称:保费试算
 * @类描述:保费试算的service
 */
@Service
public class CarQuotePriceService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private LogService logService;
    /**
     * 系统配置参数服务
     */
    @Autowired
    private SystemConfigService systemConfigService;

    @Autowired
    private IusServiceImpl iusService ;

    /**
     * @param request {@link CarQuotePriceRequest}
     * @return {@link CarQuotePriceResponse}
     * @throws BusinessException
     * @需求名称：保费试算
     * @描述:保费试算的实现方法
     */
    public CarQuotePriceResponse carQuotePrice(CarQuotePriceRequest request) throws BusinessException {
        //保费试算返回对象
        CarQuotePriceResponse response = new CarQuotePriceResponse();
        CarQuotePriceResponseMain responseBody = new CarQuotePriceResponseMain();
        response.setResponseBody(responseBody);
        //核心保费试算dubbo服务参数
   //     PolicyAppRequestParaVO policyAppRequestParaVO = null;
        //保费试算流程组件
     //   List<CarQuotePriceTransformerService> transformerList = null;
//        try {
//            //生成保费试算流程组件
//            transformerList = this.transformerListGeneration(request);
//            //循环遍历保费试算组件
//            if (transformerList != null && !transformerList.isEmpty()) {
//                for (CarQuotePriceTransformerService transformer : transformerList) {
//                    policyAppRequestParaVO = transformer.transformer(request, response, policyAppRequestParaVO);
//                }
//            }
//            //重新算费
//            if (this.ifCalcPremiumAgain(request, response)) {
//                logger.info(System.getProperty("line.separator") + "----------------------------------------保费试算二次算费请求----------------------------------------" + System.getProperty("line.separator") + CommonUtil.dto2xml(request) + System.getProperty("line.separator") + "----------------------------------------保费试算二次算费请求----------------------------------------" + System.getProperty("line.separator"));
//                // add by yangwentao reason:RM-3612 渠道平台新增时间戳日志-渠道平台  评审人:李振民  评审日期:2018-01-03 date：2017-12-28 begin
//                long firstTime = System.currentTimeMillis();
//                // add by yangwentao reason:RM-3612 渠道平台新增时间戳日志-渠道平台  评审人:李振民  评审日期:2018-01-03 date：2017-12-28 end
//
//                for (CarQuotePriceTransformerService transformer : transformerList) {
//                    policyAppRequestParaVO = transformer.transformer(request, response, policyAppRequestParaVO);
//                }
//                // add by yangwentao reason:RM-3612 渠道平台新增时间戳日志-渠道平台   评审人:李振民  评审日期:2018-01-03 date：2017-12-28 begin
//                Map<Object, Obj   ect> map = request.getRequestBody().getMap();
//                CommonUtil.timeLog(firstTime, "secondCarQuotePriceUseTime", map);
//                // add by yangwentao reason:RM-3612 渠道平台新增时间戳日志-渠道平台   评审人:李振民  评审日期:2018-01-03 date：2017-12-28 end
//                logger.info(System.getProperty("line.separator") + "----------------------------------------保费试算二次算费返回----------------------------------------" + System.getProperty("line.separator") + CommonUtil.dto2xml(response) + System.getProperty("line.separator") + "----------------------------------------保费试算二次算费返回----------------------------------------" + System.getProperty("line.separator"));
//                // add by duanguolong reason:转保业务ocr自动识别  date:2017-08-29 begin
//                //判断为转保错误信息  进行第二次算费   段国龙 start
//                if (carQuotePriceCheckCodeService.carQuotePriceCheckCode(response, request)) {
//                    Map<String, String> allresultkey = carQuotePriceCheckCodeService.carQuotePriceCallCheckCode(response, request);
//                    int CheckCodeCirculationTime = Integer.valueOf(systemConfigService.getProperty("CheckCodeCirculationTime"));
//                    boolean flag = true;
//                    int count = 1;
//                    do {
//                        logger.info(System.getProperty("line.separator") + "----------------------------------------转保保费试算二次算费请求----------------------------------------" + System.getProperty("line.separator") + CommonUtil.dto2xml(request) + System.getProperty("line.separator") + "----------------------------------------转保保费试算二次算费请求----------------------------------------" + System.getProperty("line.separator"));
//                        for (CarQuotePriceTransformerService transformer : transformerList) {
//                            policyAppRequestParaVO = transformer.transformer(request, response, policyAppRequestParaVO);
//                        }
//                        logger.info(System.getProperty("line.separator") + "----------------------------------------转保保费试算二次算费返回----------------------------------------" + System.getProperty("line.separator") + CommonUtil.dto2xml(response) + System.getProperty("line.separator") + "----------------------------------------转保保费试算二次算费返回----------------------------------------" + System.getProperty("line.separator"));
//                        if (flag) {
//                            Map<String, Boolean> flagMap = carQuotePriceCheckCodeService.inFormAutomatic(response, allresultkey);
//                            if (flagMap.get("JQRight") && flagMap.get("SYRight")) {
//                                break;
//                            }
//                        }
//                        allresultkey.clear();
//                        flag = carQuotePriceCheckCodeService.callBackCheckCode(request, response);
//                        allresultkey = carQuotePriceCheckCodeService.callBackCheckCodeTwo(request, response);
//                        count++;
//                    } while (count <= CheckCodeCirculationTime);
//                    //段国龙 转保业务二次算费  end
//                    // add by duanguolong reason:转保业务ocr自动识别  date:2017-08-29 end
//                }
//
//            } else {
//                //判断初登日期不一致给出提示信息
//                this.ifJudgeTocFstRegYm(request, response);
//            }
//            } catch (BusinessException e) {
//            logger.info(SystemParamFinal.Exception_LOG, e);
//            throw e;
//        } catch (Exception e) {
//            logger.info(SystemParamFinal.Exception_LOG, e);
//            throw new BusinessException(SystemParamFinal.BUSINESS_EXCEPTION_0039);
//        }
        //查询保险协议
        String str = request.getRequestBody().getBaseVO().getChannelAgreeCode();
        ArraySaleInformationVo av = new ArraySaleInformationVo();
        List<SaleBXInformationVo> array = new ArrayList<SaleBXInformationVo>();
        try {
            array = iusService.selectInsuredAgree(str);
        } catch (Exception e) {
            throw new BusinessException(SystemParamFinal.BUSINESS_EXCEPTION_0039,"保费试算流程异常");
      }
                    av.setSaleList(array);
                PackageJQVO jqvo =new PackageJQVO();
                PackageSYVO syvo = new PackageSYVO();
        //假数据
        CvrgVO cvrgVO = new CvrgVO();
        cvrgVO.setChannelAgreeCode(array.get(0).getChannelAgreeCode());
        cvrgVO.setChannelAgreeName(array.get(0).getChannelAgreeName());
        cvrgVO.setcCvrgNo("030000");
        cvrgVO.setcCustCvrgNme("机动车交通事故强制责任险");
        cvrgVO.setnAmt("122000.0");
        cvrgVO.setcDductMrk("369004");
        cvrgVO.setcDductMrk("369004");
        cvrgVO.setNrate("0.0");
        cvrgVO.setnBasePrm("950.0");
        cvrgVO.setnBefPrm("950.0");
        cvrgVO.setnDductRate("0.2");
        cvrgVO.setnPrm("950.0");
        cvrgVO.setnLiabDaysLmt("0");
        cvrgVO.setnPerAmt("0.0");
        cvrgVO.setnDeductibleRate("");
        cvrgVO.setnResvNum13("0");
        cvrgVO.setnDductPrm("0");
        cvrgVO.setnBasePurePrm("0");
        CvrgVO cvrgVO1 = new CvrgVO();
        cvrgVO1.setcCvrgNo("033001");
        cvrgVO1.setcCustCvrgNme("车辆损失险");
        cvrgVO.setnAmt("122800.0");
        cvrgVO1.setcDductMrk("369003");
        cvrgVO1.setNrate("0.0");
        cvrgVO1.setnBasePrm("6498.2424");
        cvrgVO1.setnBefPrm("9997.3");
        cvrgVO1.setnDductRate("0.15");
        cvrgVO1.setnPrm("9997.3");
        cvrgVO1.setnLiabDaysLmt("0");
        cvrgVO1.setnPerAmt("0.0");
        cvrgVO1.setNrate032618("");
        cvrgVO1.setnDeductibleRate("");
        cvrgVO1.setnResvNum13("0");
        cvrgVO1.setnDductPrm("1499.6");
        cvrgVO1.setnBasePurePrm("6498.2424");
        cvrgVO1.setnAllPrm("");

        CvrgVO cvrgVO2 = new CvrgVO();
        cvrgVO2.setcCvrgNo("033002");
        cvrgVO2.setcCustCvrgNme("第三者责任险");
        cvrgVO2.setnAmt("300000.0");
        cvrgVO2.setcDductMrk("369003");
        cvrgVO2.setNrate("0.0");
        cvrgVO2.setnBasePrm("867.75");
        cvrgVO2.setnBefPrm("1335.0");
        cvrgVO2.setnDductRate("0.15");
        cvrgVO2.setnPrm("1335.0");
        cvrgVO2.setnLiabDaysLmt("0");
        cvrgVO2.setnPerAmt("0.0");
        cvrgVO2.setNrate032618("");
        cvrgVO2.setnDeductibleRate("");
        cvrgVO2.setnResvNum13("0");
        cvrgVO2.setnDductPrm("200.25");
        cvrgVO2.setnBasePurePrm("0");
        cvrgVO2.setnAllPrm("");

        CvrgVO cvrgVO3 = new CvrgVO();
        cvrgVO3.setcCvrgNo("033018");
        cvrgVO3.setcCustCvrgNme("不计免赔特约险");
        cvrgVO3.setnAmt("0.0");
        cvrgVO3.setcDductMrk("369004");
        cvrgVO3.setNrate("0.0");
        cvrgVO3.setnBasePrm("0");
        cvrgVO3.setnBefPrm("1699.85");
        cvrgVO3.setnDductRate("0");
        cvrgVO3.setnPrm("1699.85");
        cvrgVO3.setnLiabDaysLmt("0");
        cvrgVO3.setnPerAmt("0.0");
        cvrgVO3.setNrate032618("");
        cvrgVO3.setnDeductibleRate("");
        cvrgVO3.setnResvNum13("0");
        cvrgVO3.setnDductPrm("0");
        cvrgVO3.setnBasePurePrm("0");
        cvrgVO3.setnAllPrm("");
     //假数据
        PrmCoefVO pv = new PrmCoefVO();pv.setDisengageFlag("1");pv.setnChannelAdjustValue("0");
        pv.setnAutonomyAdjustValue("0");pv.setnAutoChaCoef("0");pv.setnResvNum4("100.0");pv.setnResvNum3("100.0");
        pv.setnEdrPrjNo("0");pv.setnAddRate("0");pv.setnClaimTime("0");pv.setcDeprotectionFlag("0");pv.setnResvNum("0");
        pv.setnTotalClaimAmount("0.0");pv.setnAutoCheCoef("0");
        pv.setcNdiscRsn("01");pv.setnTotDisc("100.0");
        //假数据
        PrmCoefVO pv1 = new PrmCoefVO();pv1.setDisengageFlag("1");pv1.setcAgoClmRec("B31");pv1.setnResvNum4("0.0");
        pv1.setnResvNum3("1.0");pv1.setcNdiscRsn("04");pv1.setnTotDisc("0.0");pv1.setnChannelAdjustValue("1.0");
        pv1.setnAutonomyAdjustValue("1.0");pv1.setnAutoChaCoef("1.0");pv1.setnAddRate("0.35");pv1.setnClaimTime("0");pv1.setcDeprotectionFlag("0");
        pv1.setnResvNum("0");pv1.setnTotalClaimAmount("0.0");
        pv1.setnAutoCheCoef("1.0");

     //假数据
        VhlVO vhlVO = new  VhlVO();
        vhlVO.setcProdPlace("0");
        vhlVO.setcEngNo("213131");
        vhlVO.setcFrmNo("1G1BL52P7TR115520");
        vhlVO.setcModelCde("DZAAVD0058");
        vhlVO.setcModelNme("速腾FV7166G轿车");
        vhlVO.setcUsageCde("364111001");
        vhlVO.setcVhlTyp("365001");
        vhlVO.setnNewPurchaseValue("122800");
        vhlVO.setcFstRegYm("2018-07-26");
        vhlVO.setnSeatNum("5");
        vhlVO.setnTonage("0.0000");
        vhlVO.setcDisplacementLvl("0");
        vhlVO.setnDisplacement("1.595");
        vhlVO.setnActualValue("122800.0");
        vhlVO.setcTravelAreaCde("0");
        vhlVO.setcGlassTyp("1");
        vhlVO.setcDevice1Mrk("0");
        vhlVO.setcRegVhlTyp("K33");
        vhlVO.setcEcdemicMrk("0");
        vhlVO.setcRiskDesc("T001");
        vhlVO.setcTfiSpecialMrk("");
        vhlVO.setcBrandId("一汽大众");
        vhlVO.setcAliasId("DZA1AV");
        //vhlVO.settTransferDate("");
        vhlVO.setcPlateBrandId("一汽大众");
        vhlVO.setcPlateModelCde("FV7166G ");
        vhlVO.setcFleetMrk("0");
        vhlVO.setnDespRate("0.006");
        //vhlVO.setcVhlPkgNO("");
        vhlVO.setcNewVhlFlag("1");
        vhlVO.setnPoWeight("1353");
        vhlVO.setcFuelType("0");
        vhlVO.setcRenewalFlag("1");
        vhlVO.setcInspectorNme("");
        vhlVO.setcInspectionCde("0");
        //vhlVO.setcInspectRec("");
        vhlVO.setcLoanVehicleFlag("0");
        vhlVO.setnResvNum2("122800");
        vhlVO.setcUseYear("373011");
        vhlVO.setnNewPurchaseRate("0");
        vhlVO.setcModelNmeJY("速腾FV7166G 时尚型");
        vhlVO.setcFamilyNme("速腾");
        //vhlVO.setcCertificateType("");
        //vhlVO.setcCertificateNo("");
        //vhlVO.settCertificateDate("");
        //vhlVO.setnNoDamageYears("");
        vhlVO.setcPlateRecde("BYQKSUUB0014");
        vhlVO.setcNoticeType("FV7166G ");
        vhlVO.setcTradeName("一汽-大众汽车有限公司");
        vhlVO.setcSeriesKindName("速腾");
        vhlVO.setnNagoActualValue("122800.0");
        vhlVO.setcRegOwner("阿达");
        vhlVO.setcPlateColor("01");
        vhlVO.setcSpecialCarFlat("0");
        vhlVO.setcRiskLevel("0");
        //vhlVO.setcFixedParkCde("");
        //vhlVO.setcBodyColor("");
        vhlVO.setHfCode("0");
        vhlVO.setcCurModelNme("速腾FV7166G轿车");
        vhlVO.setAdjustPOrQ("0");
        vhlVO.setcCertificateDate("2018-07-26");
        vhlVO.setcVehicleCode("DZAAVD0058");

        //假数据
        VsTaxVO vsTaxVO = new VsTaxVO();
        vsTaxVO.settTaxEffBgnTm("20180701000000");
        vsTaxVO.settTaxEffEndTm("20181231000000");
        vsTaxVO.setnAnnUnitTaxAmt("300.0");
        vsTaxVO.setnTaxableAmt("150.0");
        vsTaxVO.setnLastYear("0.0");
        vsTaxVO.setnOverdueAmt("0.0");
        vsTaxVO.setcTaxUnit("300.0");
        vsTaxVO.setnAggTax("150.0");
        vsTaxVO.setcTaxdptVhltyp("3T1202");
        vsTaxVO.setcPaytaxTyp("03");
        vsTaxVO.setcVsTaxMrk("02");
        vsTaxVO.setcTaxableTyp("1");
        vsTaxVO.setcAbateProp("0.0");
        vsTaxVO.setcAbateAmt("0.0");
        vsTaxVO.setnTaxDue("0.0");
        //假数据
        BaseVO baseVO = new BaseVO();
        baseVO.setcDptCde("JJGS");
        baseVO.setcBrkrCde("DA000001");
        baseVO.setcOprCde("000255");
        baseVO.setcChaType("0101");
        baseVO.setcSlsId("600097");
        baseVO.setcBrkSlsCde("DA000001");
        baseVO.setcApproveCde("000255");
        baseVO.setcDataSrc("04");
        baseVO.setcAreaFlag("130100");
        baseVO.setcCountryFlag("130110");
        baseVO.setcImmeffMrk("0");
        baseVO.setcProvince("130000");
        baseVO.setcResvTxt9("DC000106");
        baseVO.setcResvTxt10("不不不");
        baseVO.setcResvTxt18("0");
        //假数据
        InsuredVO insuredVO = new InsuredVO();
        insuredVO.setcInsuredNme("阿达");
        //假数据
        VhlownerVO vhlownerVO = new VhlownerVO();
        vhlownerVO.setcOwnerNme("阿达");
        vhlownerVO.setcCertfCls("120002");
        vhlownerVO.setcCertfCde("2131313");
        vhlownerVO.setcVhlOwnerCate("1");
        ArrayOfCvrgVO aav = new ArrayOfCvrgVO();
        ArrayOfCvrgVO aav1 = new ArrayOfCvrgVO();
        List<CvrgVO> list = new ArrayList<CvrgVO>();
        List<CvrgVO> list1 = new ArrayList<CvrgVO>();
        list.add(cvrgVO);
        list1.add(cvrgVO1);list1.add(cvrgVO2);list1.add(cvrgVO3);
        aav.setCvrgList(list);
        aav1.setCvrgList(list1);
        //假数据

        syvo.setcAppNo("00200000103301120181423164");
        syvo.setcProdNo("033011");
        syvo.settInsrncBgnTm("20180727000000");
        syvo.settInsrncEndTm("20190726235959");
        syvo.setcQryCde("V0101APIC130018001532540174419");
        syvo.setFeeProp("0");
        syvo.setnIrrRatio("100.0");
        syvo.setnBasePrm("13032.15");
        syvo.setnPrm("13032.15");
        syvo.setFlag("1");
        syvo.setChannelCode("B2B");
        syvo.setMoneyFreshFlg("1");
        syvo.setArrayList(av);
        syvo.setBaseVO(baseVO);
        syvo.setPrmCoefVO(pv1);
        syvo.setVhlVO(vhlVO);
        syvo.setVsTaxVO(vsTaxVO);
        syvo.setInsuredVO(insuredVO);
        syvo.setVhlownerVO(vhlownerVO);
        syvo.setArrayOfCvrgVO(aav1);
      //假数据
        jqvo.setnFundRate("0.0"); jqvo.setnFundAmount("0.0");jqvo.setnIrrRatio("0.0"); jqvo.setnBasePrm("950.0");
        jqvo.setnPrm("950.0");jqvo.setFlag("1");jqvo.setChannelCode("B2B");
        jqvo.setcInvType("1"); jqvo.setAppStatus("1");
        jqvo.setcHeckCode("1");jqvo.setMoneyFreshFlg("1"); jqvo.setcAppValidateNo("12354");jqvo.setcImmeffMrk("1");jqvo.settInsrncBgnTm("20180727000000");
        jqvo.setcAppNo("00200000103000120181357882");jqvo.setcProdNo("030001");jqvo.settInsrncEndTm("20190726235959");jqvo.setcPlyTyp("1");
        jqvo.setFeeProp("0");jqvo.setcQryCde("01APIC130018001532588249922254");jqvo.setBaseVO(baseVO);jqvo.setPrmCoefVO(pv);jqvo.setVhlVO(vhlVO);jqvo.setVsTaxVO(vsTaxVO);jqvo.setInsuredVO(insuredVO);
        jqvo.setVhlownerVO(vhlownerVO);jqvo.setArrayOfCvrgVO(aav);jqvo.setArrayList(av);
        response.getResponseBody().setPackageJQVO(jqvo);
        response.getResponseBody().setPackageSYVO(syvo);
        return response;
    }


}
